package http

import (
	"gitee/com.xiaoxin/go-send/model"
	"gitee/com.xiaoxin/go-send/service"
	"github.com/gin-gonic/gin"
)

type Controller struct {
	service service.HttpService
}

func NewController() *Controller {
	return &Controller{
		service: service.NewHttpService(),
	}
}

func (controller *Controller) RegisterRoute(g *gin.RouterGroup) {
	group := g.Group("http")
	group.POST("/request", controller.Request)
}

func (controller *Controller) Request(c *gin.Context) {
	var requestInfo *model.RequestInfo = &model.RequestInfo{}
	if err := c.ShouldBindJSON(requestInfo); err != nil {
		c.JSON(400, gin.H{"error": err.Error()})
		return
	}
	responseInfo := controller.service.Request(*requestInfo)
	var resp model.Response = model.Response{
		Data:       responseInfo,
		ResultCode: 200,
		ResultDesc: "success",
	}
	c.JSON(200, resp)
}
